from django.db import models

from utils.base_models import BaseModel


class Bug(BaseModel):
    CHOICES = [
        ('未处理', '未处理'),
        ('处理中', '处理中'),
        ('处理完', '处理完'),
        ('无效bug', '无效bug'),
    ]
    # 项目
    project = models.ForeignKey(to='projects.Project', on_delete=models.CASCADE, help_text='项目id',
                                verbose_name='项目id')
    # 接口
    interface = models.ForeignKey(to='interfaces.Interface', on_delete=models.CASCADE, help_text='接口',
                                  verbose_name='接口')
    # bug描述
    desc = models.TextField(help_text='bug描述', verbose_name='bug描述', max_length=3000, blank=True)
    # bug基本信息（请求头 请求体 请求方式  响应结果）
    info = models.JSONField(help_text='测试报告', verbose_name='测试报告', default=dict, blank=True)
    # bug状态（待提交，已提交  处理中  关闭  无效bug）
    status = models.CharField(verbose_name='状态', help_text='bug状态', max_length=40, choices=CHOICES,
                              default='未处理')
    user = models.ForeignKey(verbose_name='提交者', help_text='提交者', to='users.User', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_bug'
        verbose_name = 'tb_bug'
        verbose_name_plural = verbose_name


class BugHandle(models.Model):
    """bug处理记录表"""
    create_time = models.DateTimeField(verbose_name='创建时间', help_text='创建时间', auto_now_add=True)
    bug = models.ForeignKey(to='bugs.Bug', on_delete=models.CASCADE, help_text='bugID', verbose_name='bugID')
    handle = models.TextField(help_text='处理操作', verbose_name='处理操作', blank=True)
    update_user = models.ForeignKey(verbose_name='更新用户', help_text='更新用户', to='users.User',
                                    on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_bug_handle'
        verbose_name = "tb_bug_handle"
        verbose_name_plural = verbose_name
